
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
      
    </style>
</head>
<body>
  <input type="text" class="gray" value= "请输入搜索关键字" id="txt">
  <script>
  var text = document.getElementById("txt");
  text.onfocus = function(){
    if (this.value === "请输入搜索关键字")
    {
      this.value = "";
      this.className = "black";
    }
  };

  text.onblur = function(){
    if (this.value === "")
    {
      this.value =  "请输入搜索关键字";
      this.className = "gray";
    }
  };


  </script>
</body>
</html>


  